//
//  TitleDateCell.m
//  MoneyIndividual
//
//  Created by Le Anh Tai on 1/13/14.
//  Copyright (c) 2014 Le Anh Tai. All rights reserved.
//

#import "TitleDateCell.h"

@implementation TitleDateCell

#pragma mark - Lifecycle
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {        
        _calendarView = [[MNCalendarView alloc] init];
        _calendarView.delegate = self;
        
        self.textField.clearButtonMode = UITextFieldViewModeNever;
    }
    
    return self;
}

- (void)setSelectedValue:(id)selectedValue
{
    if (selectedValue)
    {
        [super setSelectedValue:selectedValue];
    }
    else
    {
        [super setSelectedValue:[NSDate date]];
    }
}

#pragma mark - Delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [super textFieldDidBeginEditing:textField];
    
    self.textField.inputView = _calendarView;
    _calendarView.selectedDate = self.selectedValue;
}

- (void)calendarView:(MNCalendarView *)calendarView didSelectDate:(NSDate *)date
{
    self.selectedValue = date;
    [self.textField resignFirstResponder];
}
@end
